/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.shape;

import br.ufmg.dees.insane.util.IMatrix;
import br.ufmg.dees.insane.util.IVector;

/** A class representing HermiteL2
 * @author CENOURA!!!
 * @since 15/12/2005
 */
public class HermiteL2 extends ShapeC1 {

	private static final long serialVersionUID = 1L;

	/* (non-Javadoc)
     * @see br.ufmg.dees.insane.shape.Shape#getShapeFunction(double[], IMatrix)
     */
    public IVector getShapeFunction(double[] g, IMatrix cN) {
            double a = g[0];
            
            IVector n = new IVector(6);
            
            double n0 = ((0.5)*(1.0-a));
            double n1 = (2.0-3.0*a+a*a*a)/4.0;
            double n2 = (1.0-a-a*a+a*a*a)/4.0;
            double n3 = ((0.5)*(1.0+a));
            double n4 = (2.0+3.0*a-a*a*a)/4.0;
            double n5 = (-1.0-a+a*a+a*a*a)/4.0;
            
            n.setElement(0,n0);
            n.setElement(1,n1);
            n.setElement(2,n2);
            n.setElement(3,n3);
            n.setElement(4,n4);
            n.setElement(5,n5);
            
            return (n);
        }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.shape.Shape#getDerivedShapeFunction(double[], IMatrix)
     */
    public IMatrix getDerivedShapeFunction(double[] g, IMatrix cN) {
        double a = g[0];
        IMatrix dl = new IMatrix(1,6);
        
        //derivadas em relacao a xi (a = xi e b = eta)
        double dl0 = ((-1)*(0.5));
        double dl1 = (-3.0+3.0*a*a)/4.0;
        double dl2 = (-1.0-2.0*a+3.0*a*a)/4.0;
        double dl3 = ((0.5));
        double dl4 = (3.0-3.0*a*a)/4.0;
        double dl5 = (-1.0+2.0*a+3.0*a*a)/4.0;
        
        //derivadas em relacao a xi na linha 0 da IMatrix
        dl.setElement(0,0,dl0);
        dl.setElement(0,1,dl1);
        dl.setElement(0,2,dl2);
        dl.setElement(0,3,dl3);
        dl.setElement(0,4,dl4);
        dl.setElement(0,5,dl5);
        
        return (dl);
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.shape.Shape#getSecondDerivedShapeFunction(double[], IMatrix)
     */
    public IMatrix getSecondDerivedShapeFunction(double[] g, IMatrix cN) {
        double a = g[0];
        IMatrix dll = new IMatrix(1,6);
        
        //derivadas segundas em relacao a xi (a = xi e b = eta)
        double dll0 = 0;
        double dll1 = (6.0*a)/4.0;
        double dll2 = (-2.0+6.0*a)/4.0;
        double dll3 = 0;
        double dll4 = (-6.0*a)/4.0;
        double dll5 = (2.0+6.0*a)/4.0;
        
        //derivadas segundas em relacao a xi na linha 0 da IMatrix
        dll.setElement(0,0,dll0);
        dll.setElement(0,1,dll1);
        dll.setElement(0,2,dll2);
        dll.setElement(0,3,dll3);
        dll.setElement(0,4,dll4);
        dll.setElement(0,5,dll5);
        
        return (dll);
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.shape.Shape#getNaturalNodalCoords()
     */
    public IMatrix getNaturalNodalCoords() {
        IMatrix natCoords = new IMatrix(1,2);
        
    //coordenadas naturais de xi
        natCoords.setElement(0,0,-1);
        natCoords.setElement(0,1,1);
        
            return natCoords;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.shape.Shape#getType()
     */
    public String getType() {
        return "HermiteL2";
    }

}
